 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
 #include <stdlib.h>

 int main(void)
 {
 /*    pid_t pid, pid_wait;

    if ((pid = fork()) < 0) {
        printf("error ocurred!\n");
    } else if (pid == 0) {
        printf("in child:my pid is %d\n", getpid());
        sleep(2);
        exit(EXIT_SUCCESS);
    } else {
        pid_wait = wait(NULL);
        printf("wait on pid: %d\n", pid_wait);
    } */

    int status;
    pid_t pc, pr;

    if ((pc = fork()) < 0) {
        printf("error ocurred!\n");
    } else if (pc == 0) {
        printf("this is child process with pid of %d.\n", getpid());
        exit(3);
    } else {
        pr = wait(&status);
        if (WIFEXITED(status)) {
            printf("the child process %d exit normally.\n", pr);
            printf("the return code is %d .\n", WEXITSTATUS(status));
        } else if (WIFSIGNALED(status)) {
            printf("the return code is %d.\n", WTERMSIG(status));
        }
    }

    return 0;
 }